package cn.iocoder.yudao.module.infra.vector.impl.mock;

import cn.hutool.core.util.RandomUtil;
import cn.iocoder.yudao.module.infra.vector.IVectorService;
import cn.iocoder.yudao.module.resource.api.model.messagecollection.VectorDoc;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@Slf4j
@Service("vector-mock-sleep")
public class MockSleepVectorServiceImpl implements IVectorService {

    @Override
    public List<VectorDoc> queryDoc(String partition,
                                    Map<String, List<? extends Number>> vectors,
                                    Map<String, Float> weights,
                                    String filter, Integer topk, Float minSimilarity,
                                    Collection<String> outputFields) {
        try {
            Thread.sleep(RandomUtil.randomInt(80, 1000));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        return null;
    }

    @Override
    public void insertDoc(String docId,
                          Map<String, Object> fields,
                          Map<String, List<? extends Number>> vectorValues) {
        try {
            Thread.sleep(RandomUtil.randomInt(80, 1000));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void updateDoc(String docId,
                          Map<String, Object> fields,
                          Map<String, List<? extends Number>> vectorValues) {
        try {
            Thread.sleep(RandomUtil.randomInt(80, 1000));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void deleteDoc(String docId) {
        try {
            Thread.sleep(RandomUtil.randomInt(80, 1000));
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

}
